<?php include COMMON_PATH.'/header.html'; ?>
<div class="page page_validation pd20">
  <p class="top-tips mb40">查看店铺资质，请先进行手机验证</p>
  <div class="weui-body certify-body">
    <div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <p id="mobile"></p>
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input autofocus="" class="weui-input" type="tel" pattern="[0-9]*" placeholder="短信输入验证码" maxlength="6" id="vCode">
        </div>
        <div class="weui-cell__ft">
          <button class="weui-vcode-btn" id="getVCode">获取验证码</button>
        </div>
      </div>
    </div>
    <div class="btn-wrapper">
      <a href="javascript:;" class="weui-btn weui-btn_disabled" id="submit">立即验证</a>
    </div>
  </div>
</div>
<?php include COMMON_PATH.'/footer.html'; ?>
<script>
  $(function() {
    var mobile = "<?php echo $dataOne['mobile'];?>";
    $('#mobile').text(mobile)

    var $submit = $('#submit'),
      $vCode = $('#vCode'),
      hasCode = false;

    //获得验证码
    $('#getVCode').on('click', function() {
      $this = $(this);
      mobileCommon.getVcode($this, '/mobile/utils/smsSend', {
        action: 'changemobileconfirm',
        mobile: mobile
      }, function(res) {
        if (mobileCommon.loginTips(res.code, res.msg)) {
          return false;
        }
        if (res.code == 1) {
          hasCode = true;
        } else if (res.code == 10003) {
          weui.topTips(res.msg, function() {
            window.location.href = '/mobile/auth/login'
          })
        } else {
          weui.topTips(res.msg)
        }
      })
    })

    function checkForm(elem, evt, isSub) {
      vCodeLen = $vCode.val().length;
      $submit.addClass('weui-btn_disabled');
      if (!hasCode) {
        weui.topTips('请先获取验证码');
        return false;
      }
      if (vCodeLen < 5) {
        if (evt.type == 'blur' && elem == 'vCode' || isSub) {
          weui.topTips('请输入5位或6位短信验证码');
        }
        return false;
      }
      $submit.removeClass('weui-btn_disabled');
      return true;
    }

    $vCode.on('input', function(e) {
      checkForm('vCode', e, false)
    })

    //立即授权
    $('#submit').on('click', function(e) {
      e.preventDefault();
      checkForm('', e, true);
      if ($(this).hasClass('weui-btn_disabled')) {
        return;
      }
      var loading = weui.loading();

      $.ajax({
        url: '/mobile/store/validation',
        dataType: 'json',
        type: 'POST',
        data: {
          code: $vCode.val(),
          mobile: mobile,
          method: 'changemobileconfirm',
        },
        success: function(req) {
          if (mobileCommon.loginTips(req.code, req.msg)) {
            return false;
          }
          if (req.code == 1) {
            window.location.href = '/mobile/store/attestinfo';
          } else {
            weui.topTips(req.msg);
          }
        },
        complete: function() {
          loading.hide()
        }
      })
    })
  })
</script>